package stu.day9_day18;

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class LeetCode876 {
    public ListNode middleNode(ListNode head) {

        ListNode node1 = head;
        ListNode node2 = head.next;

        while (node2!=null){
            node1 = node1.next;
            node2 = node2.next==null?null:node2.next.next;

        }
        return node1;

    }
}